import java.util.Random;
import java.util.Scanner;
public class Game {
    public static void main(String[] args) {
        int w = 0;//玩家获胜场数
        int d = 0;//玩家平局场数
        //利用Random 类中的 nextInt(int)方法，随机生成1-3个数字（1.石头；2.剪刀；3.布）
        System.out.println("开始游戏->");
        System.out.println("《石头，剪刀，布》");
        Scanner peo = new Scanner(System.in);
        //进行五轮游戏
        for (int i = 1; i <= 5; i++) {
            System.out.println("第"+i+"局");
            String enter = peo.next();//接受玩家输入的字符
            int randomNumber = new Random().nextInt(3);
            if (enter.equals("石头")) {
                if (randomNumber == 1) {
                    System.out.println("电脑：石头");
                    System.out.println("平局");
                    d++;
                } else if (randomNumber == 2) {
                    System.out.println("电脑：剪刀");
                    System.out.println("你输了");
                } else if (randomNumber == 3) {
                    System.out.println("电脑：布");
                    System.out.println("你赢了");
                    w++;
                }
            } else if (enter.equals("剪刀")) {
                if (randomNumber == 1) {
                    System.out.println("电脑：石头");
                    System.out.println("你输了");
                } else if (randomNumber == 2) {
                    System.out.println("电脑：剪刀");
                    System.out.println("平局");
                    d++;
                } else if (randomNumber == 3) {
                    System.out.println("电脑：布");
                    System.out.println("你输了");
                }
            } else if (enter.equals("布")) {
                if (randomNumber == 1) {
                    System.out.println("电脑：石头");
                    System.out.println("你赢了");
                    w++;
                } else if (randomNumber == 2) {
                    System.out.println("电脑：剪刀");
                    System.out.println("你输了");
                } else if (randomNumber == 3) {
                    System.out.println("电脑：布");
                    System.out.println("平局");
                    d++;
                }
            } else {
                System.out.println("输入错误！");
            }
            System.out.println("在本局游戏中，你获胜了"+w+"局，平局了"+d+"局");
            System.out.println("--------------------------------------");
        }
        if (w>(5-w-d) ) {
            System.out.println("你获胜了！");
        }else if(w==(5-w-d)) {
            System.out.println("和局！");
        }else{
            System.out.println("电脑获胜！");
        }

    }
}
